import { defineStore } from 'pinia'

export interface Question {
  id: number
  title: string
  answer: string
  choiceList: { id: number; title: string }[]
}

export interface Choice {
  id: number
  title: string
}

export const useQuestionStore = defineStore('question', {
  state: (): { currentQuestionId: number; questionList: Question[] } => ({
    currentQuestionId: 1,
    questionList: [
      {
        id: 1,
        title: '你叫什么名字？',
        answer: '我的名字是 Vue',
        choiceList: [
          { id: 1, title: 'Vue' },
          { id: 2, title: 'React' },
          { id: 3, title: 'Angular' },
        ],
      },
      {
        id: 2,
        title: '你几岁了？',
        answer: '我三岁了',
        choiceList: [
          { id: 1, title: '1岁' },
          { id: 2, title: '2岁' },
          { id: 3, title: '3岁' },
        ],
      },
      {
        id: 3,
        title: '你最喜欢的颜色是什么？',
        answer: '我最喜欢的颜色是蓝色',
        choiceList: [
          { id: 1, title: '红色' },
          { id: 2, title: '蓝色' },
          { id: 3, title: '绿色' },
        ],
      },
      {
        id: 4,
        title: '你住在哪里？',
        answer: '我住在旧金山',
        choiceList: [
          { id: 1, title: '纽约' },
          { id: 2, title: '旧金山' },
          { id: 3, title: '洛杉矶' },
        ],
      },
      {
        id: 5,
        title: '你的职业是什么？',
        answer: '我是软件开发工程师',
        choiceList: [
          { id: 1, title: '设计师' },
          { id: 2, title: '软件开发工程师' },
          { id: 3, title: '项目经理' },
        ],
      },
      {
        id: 6,
        title: '你最喜欢的食物是什么？',
        answer: '我最喜欢的食物是比萨',
        choiceList: [
          { id: 1, title: '比萨' },
          { id: 2, title: '寿司' },
          { id: 3, title: '汉堡' },
        ],
      },
      {
        id: 7,
        title: '你最喜欢的动物是什么？',
        answer: '我最喜欢的动物是狗',
        choiceList: [
          { id: 1, title: '猫' },
          { id: 2, title: '狗' },
          { id: 3, title: '鸟' },
        ],
      },
    ],
  }),

  getters: {
    getQuestionList: (state) => state.questionList,
    getQuestionById: (state) => (id: number) => {
      return state.questionList.find((question) => question.id === id)
    },
  },

  actions: {
    incrementQuestionId() {
      this.currentQuestionId++
    },
  },
})
